package com.hj.dapp.business.budget.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hj.dapp.business.budget.mapper.BudgetItemMapper;
import com.hj.dapp.business.budget.model.BudgetItem;
import com.hj.dapp.business.budget.service.BudgetItemService;
import com.hj.dapp.business.budget.vo.BudgetProjectSave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2024/1/24
 */
@Service
public class BudgetItemServiceImpl implements BudgetItemService {
    @Autowired
    private BudgetItemMapper budgetItemMapper;

    @Override
    public void save(BudgetItem budgetItem) {
        budgetItemMapper.insert(budgetItem);
    }

    @Override
    public void deleteRel(Long id, Long projectId) {
        QueryWrapper<BudgetItem> wrapper = new QueryWrapper<>();
        wrapper.eq("budget_id", id);
        wrapper.eq("project_id", projectId);
        budgetItemMapper.delete(wrapper);
    }

    @Override
    public void deleleBindRel(Long budgetId, List<Long> projects) {
        QueryWrapper<BudgetItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("budget_id", budgetId);
        queryWrapper.notIn("project_id", projects);
        budgetItemMapper.delete(queryWrapper);
    }

}
